﻿namespace Core.Bind
{
    public class IntegerFormatBinder : AbstractBinder
    {
        public IBindText Target;
        public DSInt Source;
        public string Format;

        public override void Bind()
        {
            Target.text = Source.ToString();
            Source.onChange += OnChangeHandler;
        }

        private void OnChangeHandler()
        {
            Target.text = Format switch
            {
                "timer" => Utils.Time.FormatMS(Source.Value * 1000),
                _ => Source.ToString()
            };
        }

        public override void UnBind()
        {
            Source.onChange -= OnChangeHandler;
        }

        public override void Dispose()
        {
            base.Dispose();

            Target = null;
            Source = null;
        }
    }
}
